package main
import (
	"reflect"
	"fmt"
	"math"
)

func main() {
	defer func() {
		if err := recover();err != nil{
			fmt.Println(err)
		}
	}()
	var num int = 100
	test1(num)
	fmt.Println(num)
}
//反射机制
func test(b interface{}){
	rType := reflect.TypeOf(b)
	fmt.Println(rType)
	rVal := reflect.ValueOf(b)
	fmt.Println(rVal.Kind())
	fmt.Printf("b's value is %v,its type is %T \n",rVal,rVal)
	newInt := rVal.Int()
	sum := math.Pi + float64(newInt)
	fmt.Println(sum)
	newInterface := rVal.Interface()
	newInt1 := newInterface.(int)
	fmt.Printf("参数b回归 newInt1，值是%d，类型是%T",newInt1,newInt1)
}

func test1(b interface{}){
	rVal := reflect.ValueOf(b)
	fmt.Printf("%v \n",rVal.Kind())
	rVal.Elem().SetInt(22) //反射应用的值 reflect: reflect.Value.SetInt using unaddressable value
	//fmt.Println(*rVal)
}